package ru.mera

import grails.test.*

class DomainsIntegrationTests extends GroovyTestCase {
    protected void setUp() {
        super.setUp()
    }

    protected void tearDown() {
        super.tearDown()
    }

    void testSaveAll() {
		def c1 = new Company(name: 'My company', desc: 'qqq www eee').save();
		def d1 = new Department(name: 'My Department 1', desc: 'qqqq').save();
		def d2 = new Department(name: 'My Department 2', desc: 'wwww').save();
		def p1 = new Project(name: 'My Project 1', desc: 'eeee').save();
		def p2 = new Project(name: 'My Project 2', desc: 'rrrr').save();
		def e1 = new Employee(firstName: 'Jan', lastName: 'Fith', email: 'qq@ww.ee', desc: 'tttt');
		assertNotNull e1.save();
		def e2 = new Employee(firstName: 'Stive', lastName: 'Black', email: 'sb@ww.ee', desc: 'nnnn').save();
		def e3 = new Employee(firstName: 'Mark', lastName: 'With', email: 'dfq@ww.ee', desc: 'tsdfsdftt').save();
		def e4 = new Employee(firstName: 'Tom', lastName: 'Red', email: 'sdfq@ww.ee', desc: 'ttdsfst').save();
		def e5 = new Employee(firstName: 'Ann', lastName: 'Green', email: 'qq@wewrwe.ee', desc: 'tsdfttt').save();
		
		c1.addToDepartments(d1);
		c1.addToDepartments(d2);
		
		d1.addToProjects(p1);
		d1.addToProjects(p2);
		
		p1.addToEmployees(e1);
		p1.addToEmployees(e2);
		p1.addToEmployees(e3);
		p1.addToEmployees(e4);
		p2.addToEmployees(e5);
		
		assertEquals 2, Company.get(c1.id).departments.size();
		assertEquals 4, Project.get(p1.id).employees.size();
    }
}
